import { Controller } from "../../mvc/core/Controller";
import { HolidayReturnHintBtn } from "../view/holidayReturn/HolidayReturnHintBtn";
import { IHolidayReturnModule } from "../../../modules/interfaces/IHolidayReturnModule";
import { IView } from "../../mvc/interfaces/IView";
import { HolidayReturnModule } from "../../../modules/HolidayReturnModule";
import { NetDispatcher } from "../../mvc/core/NetDispatcher";
import { ServerCommand } from "../mvc/ServerCommand";
import { Dispatcher } from "../../mvc/core/Dispatcher";
import { EventName } from "../mvc/EventName";
import { DataEvent } from "../events/DataEvent";
import { GameProxy } from "../mvc/GameProxy";
import { HolidayReturnConfig } from "../resource/HolidayReturnConfig";
import { HolidayReturnData } from "../view/holidayReturn/HolidayReturnData";
import { THolidayRetConfig } from "../../../Message/Db/Tables/THolidayRetConfig";
import { SActiveToClient } from "../../../Message/Public/SActiveToClient";
import { EActiveType } from "../../../Message/Public/EActiveType";
import { ClockManager } from "../manager/ClockManager";
import { EHolidayRetGiftBagStatus } from "../../../Message/Public/EHolidayRetGiftBagStatus";
import { EffectManager } from "../manager/EffectManager";
import { FilterConst } from "../../component/gconst/FilterConst";
type int = number;
//class HolidayReturnController
    
    export  class HolidayReturnController extends Controller
    {
       

        public get hintBtn(): HolidayReturnHintBtn
        {
            if (!this._hintBtn) 
            {
                this._hintBtn = new HolidayReturnHintBtn();
            }
            return this._hintBtn;
        }

        public get holidayReturn(): IHolidayReturnModule
        {
            if (null == this._holidayReturnModule) 
            {
                this.initView();
            }
            return this._holidayReturnModule;
        }

        public /* override */ get view(): IView
        {
            return this.initView();
        }

        protected /* override */ initView(): IView
        {
            if (null == this._holidayReturnModule) 
            {
                this._holidayReturnModule = new HolidayReturnModule();
            }
            return this._holidayReturnModule;
        }

        protected /* override */ initServer(): void
        {
            super.initServer();
            NetDispatcher.addCmdListener(ServerCommand.ActiveTypeHolidayReturn, this.onActiveTypeHolidayReturn);
            Dispatcher.addEventListener(EventName.HolidayReturnGetStatus, this.onHolidayReturnGetStatus);
            Dispatcher.addEventListener(EventName.HolidayReturnGetStatusSucess, this.onHolidayReturnGetStatusSucess);
            Dispatcher.addEventListener(EventName.HolidayReturnGetGifBag, this.onHolidayReturnGetGifBag);
            Dispatcher.addEventListener(EventName.HolidayReturnGetGifBagSucess, this.onHolidayReturnGetGifBagSucess);
            return;
        }

        /* internal  */onHolidayReturnGetGifBagSucess(arg1: DataEvent): void
        {
            var loc3=null;
            var loc1=arg1.data.num as int;
            var loc2=arg1.data.bagStatus as Map<any, any> /* flash.utils.Dictionary */;
            cache.role.holidayReturnDic = loc2;
            this.checkBtnShine(loc2);
            if (!this.holidayReturn.isHide) 
            {
                loc3 = this.getShowArr(loc2, loc1);
                this.holidayReturn.updateStatus(loc3);
            }
            return;
        }

        /* internal  */onHolidayReturnGetGifBag(arg1: DataEvent): void
        {
            var loc1=arg1.data as int;
            GameProxy.roleProxy.getHolidayRetGiftBag(loc1);
            return;
        }

        /* internal  */onHolidayReturnGetStatusSucess(arg1: DataEvent): void
        {
            var loc3=null;
            var loc1=arg1.data.open as Boolean;
            var loc2=arg1.data.bagStatus as Map<any, any> /* flash.utils.Dictionary */;
            cache.role.holidayReturnDic = loc2;
            this.checkBtnShine(loc2);
            if (loc1) 
            {
                loc3 = this.getShowArr(loc2);
                this.holidayReturn.updateStatus(loc3);
                if (this._activeToClient) 
                {
                    this.holidayReturn.updateActTimeTx(this._activeToClient);
                }
                this.holidayReturn.show();
            }
            return;
        }

        /* internal  */getShowArr(arg1: Map<any, any> /* flash.utils.Dictionary */, arg2: int=-1): Array<any>
        {
            var loc4=null;
            var loc5=0;
            var loc1=[];
            var loc2;
            var loc3=(loc2 = HolidayReturnConfig.instance.giftArr).length;
            var loc6=0;
            while (loc6 < loc3) 
            {
                (loc4 = new HolidayReturnData()).tHolidayReturn = loc2[loc6];
                loc5 = (loc2[loc6] as THolidayRetConfig).id;
                loc4.btnStatus = arg1[loc5];
                if (loc6 + 1 != arg2) 
                {
                    loc4.isFly = false;
                }
                else 
                {
                    loc4.isFly = true;
                }
                loc1.push(loc4);
                ++loc6;
            }
            return loc1;
        }

        /* internal  */onHolidayReturnGetStatus(arg1: DataEvent): void
        {
            var loc1=arg1.data as Boolean;
            this.getStatus(loc1);
            return;
        }

        /* internal  */getStatus(arg1: Boolean): void
        {
            GameProxy.roleProxy.holidayRetGiftBagStatus(arg1);
            return;
        }

        /* internal  */onActiveTypeHolidayReturn(arg1: Object): void
        {
            this._activeToClient = arg1 as SActiveToClient;
            var loc1=cache.active.isActiveInEffect(EActiveType._EActiveTypeHolidayReturnGiftBag);
            if (loc1) 
            {
                ClockManager.instance.addDateCall(this._activeToClient.endDt, this.removeActive);
                this.hintBtn.show();
                this.getStatus(false);
            }
            else if (this._hintBtn) 
            {
                this._hintBtn.hide();
            }
            return;
        }

        /* internal  */removeActive(): void
        {
            this.hintBtn.hide();
            if (!this.view.isHide) 
            {
                this.view.hide();
            }
            return;
        }

        /* internal  */checkBtnShine(arg1: Map<any, any> /* flash.utils.Dictionary */): void
        {
            var loc1=false;
            var loc2=0;
            if (!arg1) 
            {
                return;
            }
            var loc3=0;
            var loc4=arg1;
            for(loc2 of loc4) 
            {
                if (loc2 != EHolidayRetGiftBagStatus._EHolidayRetGiftBagAvailable) 
                {
                    continue;
                }
                loc1 = true;
                break;
            }
            if (loc1) 
            {
                EffectManager.glowFilterReg(this.hintBtn, [FilterConst.guideTipsFilter]);
            }
            else 
            {
                EffectManager.glowFilterUnReg(this.hintBtn);
            }
            return;
        }

        private /* var */_holidayReturnModule: IHolidayReturnModule;

        private /* var */_hintBtn: HolidayReturnHintBtn;

        private /* var */_activeToClient: SActiveToClient;
    }
